package com.efesco.payroll.send;

import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.common.*;
import com.efesco.common.Tools;

/**
 * SendQuery_datasetSingleSendListener
 */
public class SendQuery_datasetSingleSendListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset) throws Exception {
     SqlDataset ds=(SqlDataset)dataset;
     
     String classId=Tools.toStr(ds.parameters().getString("wa_class_id"));
     String companyId=Tools.toStr(ds.parameters().getString("single_company_id"));
     String ym1 = Tools.toStr(ds.parameters().getString("year_month1"));    
     String ym2 = Tools.toStr(ds.parameters().getString("year_month2"));  
     String paymentMonth1 = Tools.toStr(ds.parameters().getString("payment_month1"));    
     String paymentMonth2 = Tools.toStr(ds.parameters().getString("payment_month2"));  
     String taxMonth1 = Tools.toStr(ds.parameters().getString("tax_month1"));    
     String taxMonth2 = Tools.toStr(ds.parameters().getString("tax_month2"));  
     String sendName=Tools.toStr(ds.parameters().getString("pay_send_name"));  

     String sql="select rownum,a.* from(select s_wa_send.WA_SEND_ID,s_wa_send.SINGLE_COMPANY_ID,"
           +"s_wa_send.WA_CLASS_ID,s_wa_send.CYEAR,s_wa_send.CMONTH,s_wa_send.payment_month,s_wa_send.tax_month,"
           +"s_wa_send.IF_CHECKOUT,s_wa_send.CHECKOUT_DATE,s_wa_send.CHECKOUT_MAN,s_wa_send.IF_EXPORT,"
           +"s_wa_send.EXPORT_DATE,s_wa_send.REMARK,s_wa_send.TS,"
           +"s_wa_send.DR,s_wa_class.WA_CLASS_NAME,s_wa_send.PAY_SEND_NAME,s_wa_send.CYEAR||s_wa_send.CMONTH THE_MONTH,s_wa_send.if_unite_tax "
           +"from s_wa_send,s_wa_class where s_wa_send.WA_CLASS_ID=s_wa_class.WA_CLASS_ID "
           +" and (s_wa_send.DR = 0) and s_wa_send.WA_CLASS_ID="+classId+" "
           +" and s_wa_send.SINGLE_COMPANY_ID="+companyId+"";
     
     if(!sendName.equals("")){
       sql+=" and s_wa_send.PAY_SEND_NAME like '%"+sendName+"%'";
     }
     if(!ym1.equals("")){
 	   sql+=" and to_char(s_wa_send.CYEAR||s_wa_send.CMONTH)>='"+ym1+"'";
     }
     if(!ym2.equals("")){
 	   sql+=" and to_char(s_wa_send.CYEAR||s_wa_send.CMONTH)<='"+ym2+"'";
     }
     if(!paymentMonth1.equals("")){
       sql+=" and s_wa_send.PAYMENT_MONTH>='"+paymentMonth1+"'";
     }
     if(!paymentMonth2.equals("")){
       sql+=" and s_wa_send.PAYMENT_MONTH<='"+paymentMonth2+"'";
     }
     if(!taxMonth1.equals("")){
       sql+=" and s_wa_send.TAX_MONTH>='"+taxMonth1+"'";
     }
     if(!taxMonth2.equals("")){
       sql+=" and s_wa_send.TAX_MONTH<='"+taxMonth2+"'";
     }
     sql+=" order by s_wa_send.cyear desc,s_wa_send.cmonth desc)a";

     ds.setSql(sql);
     
     return true;
  }

  public void afterLoadData(Dataset dataset)
     throws Exception {

  }

}
